package handler

import (
	"blog_go/pkg/helper/jwt"
	"blog_go/pkg/log"

	"github.com/gin-gonic/gin"
)

type Handler struct {
	logger *log.Logger
	jwt    *jwt.JWT
}

func NewHandler(logger *log.Logger, jwt *jwt.JWT) *Handler {
	return &Handler{
		logger: logger,
		jwt:    jwt,
	}
}

func GetUserIdFromCtx(ctx *gin.Context) int {
	v, exists := ctx.Get("claims")
	if !exists {
		return 0
	}
	return v.(*jwt.MyClaims).UserId
}

func GetUserTypeFromCtx(ctx *gin.Context) int {
	v, exists := ctx.Get("claims")
	if !exists {
		return -1
	}
	return v.(*jwt.MyClaims).UserType
}
